package projectEuler.net;

public class Problem_049 {
	private static int[] findListOf4DigitPrimes(){
		int index =0;
		int[] lstTmp = PrimesGenerator.generatePrimes(10000);
		for(int i=lstTmp.length-1; lstTmp[i]>1000 ; i--, index++);
		int[] rstTmp = new int[index];
		for(int i=lstTmp.length-1; lstTmp[i]>1000 ; i--, index--)
			rstTmp[index-1] = lstTmp[i];
		return rstTmp;
	}
	public static boolean isTwoPermulation(int abc, int def){
		int[] checkabc = new int[10];
		int[] checkdef = new int[10];
		for(int i=0; i<10; i++) checkabc[i]=checkdef[i]=0;
		for(;abc>0; abc/=10)checkabc[abc%10]++;
		for(;def>0; def/=10)checkdef[def%10]++;
		for(int i=0; i<10; i++)
			if(checkabc[i]!=checkdef[i]) return false;
		return true;
	}
	public static void checkOutAll4DigitPrimes() {
		int[] tmp = findListOf4DigitPrimes();
		for(int i= 0; i<tmp.length-2; i++)
			for(int j=i+1; j<tmp.length-1; j++)
				if(isTwoPermulation(tmp[i], tmp[j])&&(tmp[j]==(tmp[i]+3330)))
//					System.out.printf("__%d__%d\n",tmp[i], tmp[j]);
					for(int k=j+1; k<tmp.length; k++)
						if(isTwoPermulation(tmp[j], tmp[k])&&(tmp[k]==(tmp[j]+3330)))
							System.out.printf("__%d__%d__%d\n",tmp[i], tmp[j], tmp[k]);
	}
}
